package com.goktech.mapper;

import com.goktech.entity.Book;
import com.goktech.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName testBookMapper
 * @Description TODO
 * @Author 邱华英
 * @Date 2022/10/3 15:12
 * @Version 1.0
 */

public class testBookMapper {
    SqlSession session = null;
    BookMapper bookMapper = null;

    @Before
    public void before() throws IOException {
        session = SqlSessionUtil.getSqlSession();
        bookMapper = session.getMapper(BookMapper.class);
    }

    @After
    public void after(){
        session.close();
    }

    @Test
    public void testinsertBook(){
        Date date = new Date();
        Book b = new Book(13,3,"1","1","1",3,3,"1",date,"1");
        System.out.println(bookMapper.insertBook(b));
    }

    @Test
    public void testupdateBook(){
        Date date = new Date();
        Book b = new Book(13,5,"1","1","1",3,3,"1",date,"1");
        System.out.println(bookMapper.updateBook(b));
    }

    @Test
    public void testdeleteBook(){
        Date date = new Date();
        Book b = new Book(13,5,"1","1","1",3,3,"1",date,"1");
        System.out.println(bookMapper.deleteBook(b));
    }

    @Test
    public void testfindByBookId(){
        Book b = new Book();
        b.setId(11);
        System.out.println(bookMapper.findByBookId(b));
    }

    @Test
    public void findByAll(){
        System.out.println(bookMapper.findByAll(0,6));
    }

    @Test
    public void testfindLikeBookName(){
        Book b = new Book();
        b.setId(11);
        b.setBName("%中%");
        System.out.println(bookMapper.findLikeBookName(b));
    }

    @Test
    public void testfindLikeAuthor(){
        Book b = new Book();
        b.setId(11);
        b.setBName("%中%");
        b.setBAuthor("%君%");
        System.out.println(bookMapper.findLikeAuthor(b));
    }

    @Test
    public void testfindByMapOne(){
        Book b = new Book();
        b.setId(11);
        b.setBName("%中%");
        System.out.println(bookMapper.findByMapOne(b));
    }

    @Test
    public void testfindByName(){
        Book b = new Book();
        b.setId(11);
        b.setBName("哈哈");
        System.out.println(bookMapper.findByName(b));
    }
}
